<?php

namespace app\admin\controller;

use app\common\controller\Backend;

/**
 * 设备mqtt
 *
 * @icon fa fa-circle-o
 */
class Socket extends Backend
{

    /**
     * Device模型对象
     * @var \app\common\model\Device
     */
    protected $model = null;

    public function _initialize()
    {
        parent::_initialize();
    }




    /**
     * 查看
     */
    public function index()
    {
            $type = $this->request->get('type');
            $device_name = $this->request->get('device_name');
            $num = $this->request->get('num',1);
            $socket_api = new \app\common\library\Socket();
            //1启动泡泡 2关闭电机 3 引流 4彩灯 5音量
            switch ($type) {
                case 1:
                    $socket_api->startDev([["device_name"=>$device_name,"type"=>1,"time"=>$num]]);
                    break;
                case 2:
                    $socket_api->stopDev($device_name,$num);
                    break;
                case 3:
                    $socket_api->awaitBeckon($device_name);
                    break;
                case 4:
                    //num 1开 0关
                    $socket_api->ledDev($device_name,$num);
                    break;
                case 5:
                    //num 0-30
                    $socket_api->volDev($device_name,$num);
                    break;
            }
            return json(['code'=>0,'msg'=>'成功','data'=>['type'=>$type,'device_name'=>$device_name,'num'=>$num]]);

    }

}
